<?php


namespace App\backend\models;

use App\common\models\BaseModel;
use Illuminate\Support\Facades\DB;

class ActivityShareModel extends BaseModel
{
    const table = 'activity_share';

    static $_instance;

    const _field = ['*'];

    public static function getInstance()
    {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    /**
     * 获取数据
     * @param $condition
     * @param $page
     * @param $limit
     * @param array $field
     * @return mixed
     */
    public function getPageList($condition, $page, $limit, array $field = self::_field)
    {
        return DB::table(self::table)->select($field)->where($condition)->apiPaginate($limit, ['*'], 'page', $page)->toarray();
    }

    /**
     * 获取数据
     * @param $condition
     * @param array $field
     * @param array $condition_in
     * @return array
     */
    public function getList($condition, array $field = self::_field, $condition_in = [])
    {
        $query = DB::table(self::table)
            ->select($field)
            ->where($condition);

        if (!empty($condition_in)) {
            foreach ($condition_in as $ksy=>$val) {
                $query->whereIn($ksy, $val);
            }
        }
        return $query->get()->toarray();
    }

    /**
     * 获取最大值
     * @param $condition
     * @return int
     */
    public function getCount($condition)
    {
        return DB::table(self::table)->where($condition)->count();
    }

    /**
     * 保存数据
     * @param $data
     * @return bool
     */
    public function insertSave($data)
    {
        if (!$data) {
            return '';
        }
        $data['create_time'] = time();
        return DB::table(self::table)->insertGetId($data);
    }


}
